import 'package:boss/color_constant.dart';
import 'package:boss/textStyle/text_style.dart';
import 'package:boss/theme/theme.dart';
import 'package:boss/ui/widget/image/base_image.dart';
import 'package:hi_common/hi_common.dart';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class DoubleFormField extends StatefulWidget {
  final String firstText;
  final String secondText;
  final String thirdText;
  final String fourthText;
  final TextInputType firstInputType;
  final TextInputType secondInputType;
  final List<TextInputFormatter> firstInputFormatters;
  final List<TextInputFormatter> secondInputFormatters;
  final String firstInitValue;
  final String secondInitValue;
  final ValueChanged<String> onFirstChanged;
  final ValueChanged<String> onSecondChanged;
  final VoidCallback onDelete;
  final int firstMaxLength;
  final int secondMaxLength;
  final bool enabled;
  final bool firstEnabled;
  final bool secondEnabled;
  final double itemHeight;

  const DoubleFormField({
    Key key,
    @required this.firstText,
    @required this.secondText,
    @required this.thirdText,
    @required this.fourthText,
    this.firstInputType,
    this.secondInputType,
    this.firstInputFormatters,
    this.secondInputFormatters,
    this.firstInitValue,
    this.secondInitValue,
    this.onFirstChanged,
    this.onSecondChanged,
    this.onDelete,
    this.firstMaxLength,
    this.secondMaxLength,
    this.enabled = true,
    this.firstEnabled = true,
    this.secondEnabled = true,
    this.itemHeight,
  }) : super(key: key);

  @override
  _DoubleFormFieldState createState() => _DoubleFormFieldState();
}

class _DoubleFormFieldState extends State<DoubleFormField> {
  @override
  Widget build(BuildContext context) {
    return Theme(
      data: lightTheme.copyWith(
        inputDecorationTheme: InputDecorationTheme(
          border: NoInputBorder(),
          hintStyle: TextStyleConstant().normal_3_28,
        ),
      ),
      child: DefaultTextStyle(
        style: TextStyleConstant().normal_1_28,
        child: Container(
          height: ScreenUtil.instance.setWidth(widget.itemHeight ?? 90),
          decoration: BoxDecoration(
              border: Border(
            bottom: BorderSide(
              color: ColorConstant.e6e6,
              width: 1.px,
            ),
          )),
          child: Row(
            children: <Widget>[
              Expanded(
                child: Row(
                  children: <Widget>[
                    Text(widget.firstText),
                    Expanded(
                      child: TextFormField(
                        textAlign: TextAlign.center,
                        style: TextStyleConstant().normal_1_28,
                        decoration: InputDecoration(
                          hintText: '请输入',
                        ),
                        keyboardType: widget.firstInputType,
                        inputFormatters: widget.firstInputFormatters,
                        initialValue: widget.firstInitValue,
                        onChanged: widget.onFirstChanged,
                        enabled: widget.enabled && widget.firstEnabled,
                      ),
                    ),
                    Text(widget.secondText),
                  ],
                ),
              ),
              Expanded(
                child: Row(
                  children: <Widget>[
                    Text(widget.thirdText),
                    Expanded(
                      child: TextFormField(
                        textAlign: TextAlign.center,
                        style: TextStyleConstant().normal_1_28,
                        decoration: InputDecoration(
                          hintText: '请输入',
                        ),
                        keyboardType: widget.secondInputType,
                        inputFormatters: widget.secondInputFormatters,
                        onChanged: widget.onSecondChanged,
                        initialValue: widget.secondInitValue,
                        enabled: widget.enabled && widget.secondEnabled,
                      ),
                    ),
                    Text(widget.fourthText),
                  ],
                ),
              ),
              widget.onDelete == null
                  ? Container()
                  : Container(
                      margin: EdgeInsets.only(
                        left: 15.w,
                      ),
                      child: GestureDetector(
                        onTap: widget.onDelete,
                        child: BaseImage(
                          'assets/image/take_out_food_close.png',
                          width: 30.w,
                          height: 30.w,
                        ),
                      ),
                    ),
            ],
          ),
        ),
      ),
    );
  }
}
